/**
 * 请求自己的多张名片
 * 得到自己的名片列表
 */
import wepy from 'wepy';

import {
  SYSTEM_INFO,
  TOKEN,
  USER_INFO,
  CARD_INFO,
  USER_SPECIAL_INFO
} from '@/utils/constant';

import api from '@/api/api';

export default class GetCardInfo extends wepy.mixin {
  data = {}

  async onShow() {
    this.userInfo = wepy.getStorageSync(USER_INFO) || {}; // 用户信息

    /*用户名片*/
    let cardInfo = wepy.getStorageSync(CARD_INFO);
    // console.log(cardInfo)
    if (cardInfo) {
      this.cardInfo = cardInfo;
    } else {
      try {
        let info = await api.index();
        if (+info.data.code === 12000) {
          //请求用户名片
          wepy.setStorageSync(CARD_INFO, info.data.data);
          this.cardInfo = info.data.data;
        }
      } catch (err) {
        console.log(err);
      }
    }

    this.$broadcast('info', cardInfo);

    console.log(this);
  }
}
